//
//  CZCollectionViewCell.m
//  HospitalSystem
//
//  Created by jss on 16/5/4.
//
//

#import "CZCollectionViewCell.h"
#import  <Masonry.h>



@interface CZCollectionViewCell ()

@property(nonatomic,weak)UIButton *btn;

@property(nonatomic,weak)UILabel *lable;

@end

@implementation CZCollectionViewCell


-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        //设置UI界面
        [self setupUI];
    }
    
    return self;
}

//设置UI界面
-(void)setupUI{

    //添加btn
    UIButton *btn = [[UIButton alloc]init];
  
    self.btn = btn;
    
    btn.imageEdgeInsets = UIEdgeInsetsMake(-20, 0, 0, 0);
    
    //给btn添加点击事件
    [btn addTarget:self action:@selector(didClickBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.contentView addSubview:btn];
    
    //添加lable
    UILabel *lable = [[UILabel alloc]init];
    lable.textAlignment = NSTextAlignmentCenter;
    
    
    self.lable = lable;
    
    [self.contentView addSubview:lable];
    
    //设置约束
    [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.equalTo(self.contentView).offset(self.bounds.size.height * 0.3);
        make.right.bottom.equalTo(self.contentView).offset(-self.bounds.size.height * 0.3);
        
    }];
    
    [_lable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(btn.mas_bottom).offset(-30);
        
        make.leading.equalTo(btn);
        make.width.equalTo(btn);
    }];
    
    


}


//实现btn的点击事件
-(void)didClickBtn:(UIButton *)btn {
    
    //CSViewController * controllerVc = [[CSViewController alloc]init];
    
    NSLog(@"点击btn");
    //发送通知
    [[NSNotificationCenter defaultCenter]postNotificationName:@"didBtn" object:nil userInfo:@{@"model":self.model}];
    

}



//重写model的set方法
-(void)setModel:(CZBtnModel *)model {
    
    _model = model;
    
    [self.btn setImage:[UIImage imageNamed:model.imgName] forState:(UIControlStateNormal)];
    
    self.lable.text = model.title;
    
 
}

@end
